local fengpo = fk.CreateSkill {

  name = "joy__fengpo",

  tags = {  },

}



fengpo:addEffect(fk.TargetSpecified, {
  name = "joy__fengpo",
  anim_type = "offensive",
  events ={fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(fengpo.name) and (data.card.trueName == "slash" or data.card.trueName == "duel") then
      local room = player.room
      local to = room:getPlayerById(data.to)
      if not to.dead and U.isOnlyTarget(to, data, event) then
        local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
        if use_event == nil then return false end
        local x = player:getMark("fengpo_record_" .. data.card.trueName.."-turn")
        if x == 0 then
          room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
            local use = e.data[1]
            if use.from == player.id and use.card.trueName == data.card.trueName then
              x = e.id
              room:setPlayerMark(player, "fengpo_record_" .. data.card.trueName.."-turn", x)
              return true
            end
          end, Player.HistoryTurn)
        end
        return x == use_event.id
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"joy__fengpo_draw", "joy__fengpo_damage", "Cancel"}, fengpo.name,
      "#fengpo-choice::"..data.to..":"..data.card:toLogString())
    if choice == "Cancel" then return false end
    room:doIndicate(player.id, {data.to})
    event:setCostData(self, choice)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(data.to)
    local n = 0
    for _, id in ipairs(to:getCardIds("h")) do
      if Fk:getCardById(id).color == Card.Red then
        n = n + 1
      end
    end
    n = math.min(4,n)
    if event:getCostData(self) == "joy__fengpo_draw" then
      if n > 0 then
        player:drawCards(n, fengpo.name)
      end
    else
      if n > 0 then
        data.additionalDamage = (data.additionalDamage or 0) + n
      end
    end
  end,
})

return fengpo